﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Tilver.Coder.Core
{
    /// <summary>
    /// 结构
    /// </summary>
    [Serializable]
    public abstract class CoderTabular : CoderObjectBase, IMOGenerable, IBuildable
    {
        //private string _nameSpace;
        ///// <summary>
        ///// 命名空间
        ///// </summary>
        //public string NameSpace
        //{
        //    get
        //    {
        //        if (string.IsNullOrEmpty(_nameSpace))
        //        {
        //            //if (!string.IsNullOrEmpty(Owner) && !Owner.Equals("dbo",StringComparison.CurrentCultureIgnoreCase))
        //            if (!string.IsNullOrEmpty(Owner))
        //            {
        //                _nameSpace = string.Format("{0}.{1}", this.DataBase.CodeName, Owner);
        //            }
        //            else
        //            {
        //                _nameSpace = this.DataBase.CodeName;
        //            }
        //        }
        //        return _nameSpace;
        //        //return string.IsNullOrEmpty(_nameSpace) ? (this.DataBase.CodeName + (string.IsNullOrEmpty(Owner) ? string.Empty : "." + Owner)) : _nameSpace;
        //    }
        //    set { _nameSpace = value; }
        //}
        /// <summary>
        /// 结构类型
        /// </summary>
        public abstract TabularTypeEnum TabularType { get; }
        /// <summary>
        /// 状态
        /// </summary>
        public ObjectStateEnum State { get; set; }

        #region IMOGenerable 成员
        /// <summary>
        /// 数据操作类信息
        /// </summary>
        public CoderMOInfo MOInfo { get; set; }

        #endregion

        #region IEOGenerable 成员
        
        private List<CoderColumn> _columns;
        /// <summary>
        /// 列集合
        /// </summary>
        public virtual List<CoderColumn> Columns
        {
            get { return _columns ?? (_columns = new List<CoderColumn>()); }
            set { _columns = value; }
        }
        /// <summary>
        /// 实体类名称
        /// </summary>
        public string EOName { get; set; }
        /// <summary>
        /// 架构名称
        /// </summary>
        public string Owner { get; set; }
        /// <summary>
        /// 全名
        /// </summary>
        public string FullName { get; set; }
        /// <summary>
        /// 是否有主健
        /// </summary>
        public virtual bool HasPrimaryKey
        {
            get { return false; }
        }
        /// <summary>
        /// 主健
        /// </summary>
        public CoderPrimaryKey PrimaryKey { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        #endregion

        #region IBuildable 成员
        /// <summary>
        /// 是否可以生成代码
        /// </summary>
        public bool IsBuild { get; set; }
        #endregion

    }
}
